package com.bootdo.system.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.bootdo.system.service.DlCompanyService;
import com.bootdo.system.vo.UpcomingListAlbum;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.ui.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bootdo.system.domain.DlCompanyAlbumDO;
import com.bootdo.system.service.DlCompanyAlbumService;
import com.bootdo.common.utils.PageUtils;
import com.bootdo.common.utils.Query;
import com.bootdo.common.utils.R;

/**
 * 
 * 
 * @author chglee
 * @email 1992lcg@163.com
 * @date 2021-06-02 13:39:39
 */
 
@Controller
@RequestMapping("/system/dlCompanyAlbum")
public class DlCompanyAlbumController {
	@Autowired
	private DlCompanyAlbumService dlCompanyAlbumService;

	@Autowired
	private DlCompanyService dlCompanyService;
	@Value("${upload.IP}")
	private String IP;

	@GetMapping()
	@RequiresPermissions("system:dlCompanyAlbum:dlCompanyAlbum")
	String DlCompanyAlbum(){
	    return "system/dlCompanyAlbum/dlCompanyAlbum";
	}
	
	@ResponseBody
	@GetMapping("/list")
	public PageUtils list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
		List<DlCompanyAlbumDO> dlCompanyAlbumList = dlCompanyAlbumService.list(query);
		int total = dlCompanyAlbumService.count(query);
		PageUtils pageUtils = new PageUtils(dlCompanyAlbumList, total);
		return pageUtils;
	}


	@ResponseBody
	@GetMapping("/upcomingList")
	public PageUtils upcomingList(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
		List<UpcomingListAlbum> dlCompanyAlbumList = dlCompanyAlbumService.upcomingList(query);
		int total = dlCompanyAlbumService.count(query);
		int count = dlCompanyService.count(query);
		PageUtils pageUtils = new PageUtils(dlCompanyAlbumList, total + count);
		return pageUtils;
	}

	@GetMapping("/todoTask")
	String DlupcomingList(){
		return "system/dlCompanyAlbum/todoTask";
	}


	@GetMapping("/auditMaterials/{companyId}")
	public String auditMaterials(@PathVariable("companyId") String companyId, Model model){
		HashMap<String, Object> s = new HashMap<>();
		s.put("companyId", companyId);
		s.put("auditStatus", "3");
		List<DlCompanyAlbumDO> list = dlCompanyAlbumService.list(s);
		for (DlCompanyAlbumDO dlCompanyAlbumDO : list) {
			dlCompanyAlbumDO.setFileName(IP + "/upload/" + dlCompanyAlbumDO.getFileName());
		}

		model.addAttribute("DlCompanyAlbumDOs", list);
		return "system/dlCompanyAlbum/edit";
	}

	/**
	 * 功能描述: 发送审核失败原因
	 * @Param:
	 * @Return:
	 * @Author: 况鑫威
	 * @Date: 2021/6/3
	 * @Time: 11:25
	 */
	@ResponseBody
	@PostMapping("/auditFailureText")
	public R auditFailureText(String auditFailureText, String id){
		dlCompanyAlbumService.auditFailureText(auditFailureText, id);
		return R.ok();
	}
	
	@GetMapping("/add")
	@RequiresPermissions("system:dlCompanyAlbum:add")
	String add(){
	    return "system/dlCompanyAlbum/add";
	}


	@GetMapping("/edit/{companyAlbumId}")
	@RequiresPermissions("system:dlCompanyAlbum:edit")
	String edit(@PathVariable("companyAlbumId") Integer companyAlbumId,Model model){
		DlCompanyAlbumDO dlCompanyAlbum = dlCompanyAlbumService.get(companyAlbumId);
		model.addAttribute("dlCompanyAlbum", dlCompanyAlbum);
	    return "system/dlCompanyAlbum/edit";
	}
	
	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	@RequiresPermissions("system:dlCompanyAlbum:add")
	public R save( DlCompanyAlbumDO dlCompanyAlbum){
		if(dlCompanyAlbumService.save(dlCompanyAlbum)>0){
			return R.ok();
		}
		return R.error();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	public R update( DlCompanyAlbumDO dlCompanyAlbum){
		dlCompanyAlbumService.update(dlCompanyAlbum);
		return R.ok();
	}

	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/updateStatus")
	public R updateStatus( @RequestParam("ids") String[] ids, @RequestParam("type") String type){
		dlCompanyAlbumService.updateStatus(ids, type);
		return R.ok();
	}


	
	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	@RequiresPermissions("system:dlCompanyAlbum:remove")
	public R remove( Integer companyAlbumId){
		if(dlCompanyAlbumService.remove(companyAlbumId)>0){
			return R.ok();
		}
		return R.error();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	@RequiresPermissions("system:dlCompanyAlbum:batchRemove")
	public R remove(@RequestParam("ids[]") Integer[] companyAlbumIds){
		dlCompanyAlbumService.batchRemove(companyAlbumIds);
		return R.ok();
	}
	
}
